package com.panels.cell;

import java.awt.Component;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

class ImageComboBoxRenderer extends JLabel
implements ListCellRenderer {
	
	ImageIcon[] images;

	public ImageComboBoxRenderer(ImageIcon[] images) {
		
		setOpaque(true);
		setHorizontalAlignment(CENTER);
		setVerticalAlignment(CENTER);
		
		this.images=images;
	}

	/*
	 * This method finds the image and text corresponding
	 * to the selected value and returns the label, set up
	 * to display the text and image.
	 */
	public Component getListCellRendererComponent(
			JList list,
			Object value,
			int index,
			boolean isSelected,
			boolean cellHasFocus) {
		//Get the selected index. (The index param isn't
		//always valid, so just use the value.)
		int selectedIndex = Integer.parseInt(((ValuePair)value).getCode());

		if (isSelected) {
			setBackground(list.getSelectionBackground());
			setForeground(list.getSelectionForeground());
		} else {
			setBackground(list.getBackground());
			setForeground(list.getForeground());
		}

		//Set the icon and text.  If icon was null, say so.
		//System.out.println(selectedIndex);
		ImageIcon icon = images[selectedIndex];
		//String pet = petStrings[selectedIndex];
		setIcon(icon);
		/*if (icon != null) {
			setText(pet);
			setFont(list.getFont());
		} else {
			setUhOhText(pet + " (no image available)",
					list.getFont());
		}*/

		return this;
	}

}